#include "gps.h"
#include <string.h>

unsigned char GPS_GGA_ON[] = {0xf1,0xd9,0x06,0x01,0x03,0x00,0xf0,0x00,0x01,0xfb,0x10,'\r'};//GGA ON
unsigned char GPS_SAVE[] = {0xf1,0xd9,0x06,0x09,0x08,0x00,0x00,0x00,0x00,0x00,0x2F,0X00,0X00,0X00,0X46,0XB7,'\r'};//GPS SAVE

// GPS命令
unsigned char GGA_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x00, 0x00, 0xFA, 0x0F,'\r'};
unsigned char GGA_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x00, 0x01, 0xFB, 0x10,'\r'};
unsigned char GLL_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x01, 0x00, 0xFB, 0x11,'\r'};
unsigned char GLL_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x01, 0x01, 0xFC, 0x12,'\r'};
unsigned char GSA_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x02, 0x00, 0xFC, 0x13,'\r'};
unsigned char GSA_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x02, 0x01, 0xFD, 0x14,'\r'};
unsigned char GSV_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x00, 0xFE, 0x17,'\r'};
unsigned char GSV_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x01, 0xFF, 0x18,'\r'};
unsigned char RMC_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x05, 0x00, 0xFF, 0x19,'\r'};
unsigned char RMC_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x05, 0x01, 0x00, 0x1A,'\r'};
unsigned char VTG_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x06, 0x00, 0x00, 0x1B,'\r'};
unsigned char VTG_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x06, 0x01, 0x01, 0x1C,'\r'};
unsigned char ZDA_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x07, 0x00, 0x01, 0x1D,'\r'};
unsigned char ZDA_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x07, 0x01, 0x02, 0x1E,'\r'};
unsigned char GST_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x08, 0x00, 0x02, 0x1F,'\r'};
unsigned char GST_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x08, 0x01, 0x03, 0x20,'\r'};
unsigned char GNTXT_OFF[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x20, 0x00, 0x1A, 0x4F,'\r'};
unsigned char GNTXT_ON[] = {0xF1, 0xD9, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x20, 0x01, 0x1B, 0x50,'\r'};
unsigned char GPS_RECOVER[] = {0xF1, 0xD9, 0x06, 0x09, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x15, 0x01,'\r'};
//unsigned char GPS_SAVE[] = {0xF1, 0xD9, 0x06, 0x09, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x46, 0xB7,'\r'};
unsigned char GPS_115200[] = {0xF1, 0xD9, 0x06, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x01, 0x00, 0xD1, 0xE0,'\r'};
unsigned char GPS_L1[] = {0xF1, 0xD9, 0x06, 0x0C, 0x04, 0x00, 0x37, 0x00, 0x00, 0x04, 0x51, 0x7C,'\r'};
unsigned char GPS_L1_L5[] = {0xF1, 0xD9, 0x06, 0x0C, 0x04, 0x00, 0x37, 0x82, 0x10, 0x04, 0xE3, 0x22,'\r'};
unsigned char GPS_BD[] = {0xF1, 0xD9, 0x06, 0x0C, 0x04, 0x00, 0x04, 0x80, 0x00, 0x00, 0x9A, 0x2C,'\r'};
unsigned char GPS_GPS[] = {0xF1, 0xD9, 0x06, 0x0C, 0x04, 0x00, 0x01, 0x02, 0x00, 0x00, 0x19, 0xA6,'\r'};

nmea_msg GPS_message;

//从buf里面得到第cx个逗号所在的位置
//返回值:0~0XFE,代表逗号所在位置的偏移.
//       0XFF,代表不存在第cx个逗号							  
uint8_t NMEA_Comma_Pos(uint8_t *buf,uint8_t cx)
{	 		    
	uint8_t *p=buf;
	while(cx)
	{		 
		if(*buf=='*'||*buf<' '||*buf>'z')return 0XFF;//遇到'*'或者非法字符,则不存在第cx个逗号
		if(*buf==',')cx--;
		buf++;
	}
	return buf-p;	 
}
//m^n函数
//返回值:m^n次方.
uint32_t NMEA_Pow(uint8_t m,uint8_t n)
{
	uint32_t result=1;	 
	while(n--)result*=m;    
	return result;
}
//str转换为数字,以','或者'*'结束
//buf:数字存储区
//dx:小数点位数,返回给调用函数
//返回值:转换后的数值
int NMEA_Str2num(uint8_t *buf,uint8_t*dx)
{
	uint8_t *p=buf;
	uint32_t ires=0,fres=0;
	uint8_t ilen=0,flen=0,i;
	uint8_t mask=0;
	int res;
	while(1) //得到整数和小数的长度
	{
		if(*p=='-'){mask|=0X02;p++;}//是负数
		if(*p==','||(*p=='*'))break;//遇到结束了
		if(*p=='.'){mask|=0X01;p++;}//遇到小数点了
		else if(*p>'9'||(*p<'0'))	//有非法字符
		{	
			ilen=0;
			flen=0;
			break;
		}	
		if(mask&0X01)flen++;
		else ilen++;
		p++;
	}
	if(mask&0X02)buf++;	//去掉负号
	for(i=0;i<ilen;i++)	//得到整数部分数据
	{  
		ires+=NMEA_Pow(10,ilen-1-i)*(buf[i]-'0');
	}
	if(flen>5)flen=5;	//最多取5位小数
	*dx=flen;	 		//小数点位数
	for(i=0;i<flen;i++)	//得到小数部分数据
	{  
		fres+=NMEA_Pow(10,flen-1-i)*(buf[ilen+1+i]-'0');
	} 
	res=ires*NMEA_Pow(10,flen)+fres;
	if(mask&0X02)res=-res;		   
	return res;
}	  							 
//分析GPGSV信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GPGSV_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p,*p1,dx;
	uint8_t len,i,j,slx=0;
	uint8_t posx;   	 
	p=buf;
	p1=(uint8_t*)strstr((const char *)p,"$GPGSV");
	len=p1[7]-'0';								//得到GPGSV语句条数
	posx=NMEA_Comma_Pos(p1,3); 					//得到可见卫星总数
	if(posx!=0XFF)gpsx->svnum=NMEA_Str2num(p1+posx,&dx);
	for(i=0;i<len;i++)
	{	 
		p1=(uint8_t*)strstr((const char *)p,"$GPGSV");  
		for(j=0;j<4;j++)
		{	  
			posx=NMEA_Comma_Pos(p1,4+j*4);
			if(posx!=0XFF)gpsx->slmsg[slx].num=NMEA_Str2num(p1+posx,&dx);	//得到卫星编号
			else break; 
			posx=NMEA_Comma_Pos(p1,5+j*4);
			if(posx!=0XFF)gpsx->slmsg[slx].eledeg=NMEA_Str2num(p1+posx,&dx);//得到卫星仰角 
			else break;
			posx=NMEA_Comma_Pos(p1,6+j*4);
			if(posx!=0XFF)gpsx->slmsg[slx].azideg=NMEA_Str2num(p1+posx,&dx);//得到卫星方位角
			else break; 
			posx=NMEA_Comma_Pos(p1,7+j*4);
			if(posx!=0XFF)gpsx->slmsg[slx].sn=NMEA_Str2num(p1+posx,&dx);	//得到卫星信噪比
			else break;
			slx++;	   
		}   
 		p=p1+1;//切换到下一个GPGSV信息
	}   
}
//分析GBGSV信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GBGSV_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p,*p1,dx;
	uint8_t len,i,j,slx=0;
	uint8_t posx;   	 
	p=buf;
	p1=(uint8_t*)strstr((const char *)p,"$GBGSV");
	len=p1[7]-'0';								//得到GBGSV的条数
	posx=NMEA_Comma_Pos(p1,3); 					//得到可见北斗卫星总数
	if(posx!=0XFF)gpsx->beidou_svnum=NMEA_Str2num(p1+posx,&dx);
	for(i=0;i<len;i++)
	{	 
		p1=(uint8_t*)strstr((const char *)p,"$GBGSV");  
		for(j=0;j<4;j++)
		{	  
			posx=NMEA_Comma_Pos(p1,4+j*4);
			if(posx!=0XFF)gpsx->beidou_slmsg[slx].beidou_num=NMEA_Str2num(p1+posx,&dx);	//得到卫星编号
			else break; 
			posx=NMEA_Comma_Pos(p1,5+j*4);
			if(posx!=0XFF)gpsx->beidou_slmsg[slx].beidou_eledeg=NMEA_Str2num(p1+posx,&dx);//得到卫星仰角 
			else break;
			posx=NMEA_Comma_Pos(p1,6+j*4);
			if(posx!=0XFF)gpsx->beidou_slmsg[slx].beidou_azideg=NMEA_Str2num(p1+posx,&dx);//得到卫星方位角
			else break; 
			posx=NMEA_Comma_Pos(p1,7+j*4);
			if(posx!=0XFF)gpsx->beidou_slmsg[slx].beidou_sn=NMEA_Str2num(p1+posx,&dx);	//得到卫星信噪比
			else break;
			slx++;	   
		}   
 		p=p1+1;//切换到下一个BDGSV信息
	}   
}
//分析GNGGA信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GNGGA_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p1,dx;		
	uint32_t temp;	   
	
	uint8_t posx;   
	float rs;  
	
	p1=(uint8_t*)strstr((const char *)buf,"$GNGGA");
	posx=NMEA_Comma_Pos(p1,1);								//得到UTC时间
	if(posx!=0XFF)
	{
		temp=NMEA_Str2num(p1+posx,&dx)/NMEA_Pow(10,dx);	 	//得到UTC时间,去掉ms
		gpsx->utc.hour=temp/10000;
		gpsx->utc.min=(temp/100)%100;
		gpsx->utc.sec=temp%100;	 	 
	}	
	
	
	posx=NMEA_Comma_Pos(p1,2);								//得到纬度
	if(posx!=0XFF)
	{
		temp=NMEA_Str2num(p1+posx,&dx);		 	 
		gpsx->latitude=temp/NMEA_Pow(10,dx+2);	//得到°
		rs=temp%NMEA_Pow(10,dx+2);				//得到'		 
		gpsx->latitude=gpsx->latitude*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为° 
	}
	posx=NMEA_Comma_Pos(p1,3);								//南纬还是北纬 
	if(posx!=0XFF)gpsx->nshemi=*(p1+posx);					 
 	posx=NMEA_Comma_Pos(p1,4);								//得到经度
	if(posx!=0XFF)
	{												  
		temp=NMEA_Str2num(p1+posx,&dx);		 	 
		gpsx->longitude=temp/NMEA_Pow(10,dx+2);	//得到°
		rs=temp%NMEA_Pow(10,dx+2);				//得到'		 
		gpsx->longitude=gpsx->longitude*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为° 
	}
	posx=NMEA_Comma_Pos(p1,5);								//东经还是西经
	if(posx!=0XFF)gpsx->ewhemi=*(p1+posx);	
	posx=NMEA_Comma_Pos(p1,6);								//得到GPS状态
	if(posx!=0XFF)gpsx->gpssta=NMEA_Str2num(p1+posx,&dx);	
	posx=NMEA_Comma_Pos(p1,7);								//得到用于定位的卫星数
	if(posx!=0XFF)gpsx->posslnum=NMEA_Str2num(p1+posx,&dx); 
	posx=NMEA_Comma_Pos(p1,9);								//得到海拔高度
	if(posx!=0XFF)gpsx->altitude=NMEA_Str2num(p1+posx,&dx);  
}	

//分析GNGSA信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GNGSA_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p1,dx;			 
	uint8_t posx; 
	uint8_t i;   
	p1=(uint8_t*)strstr((const char *)buf,"$GNGSA");
	posx=NMEA_Comma_Pos(p1,2);								//得到定位类型
	if(posx!=0XFF)gpsx->fixmode=NMEA_Str2num(p1+posx,&dx);	
	for(i=0;i<12;i++)										//得到定位卫星编号
	{
		posx=NMEA_Comma_Pos(p1,3+i);					 
		if(posx!=0XFF)gpsx->possl[i]=NMEA_Str2num(p1+posx,&dx);
		else break; 
	}				  
	posx=NMEA_Comma_Pos(p1,15);								//得到PDOP位置精度因子
	if(posx!=0XFF)gpsx->pdop=NMEA_Str2num(p1+posx,&dx);  
	posx=NMEA_Comma_Pos(p1,16);								//得到HDOP位置精度因子
	if(posx!=0XFF)gpsx->hdop=NMEA_Str2num(p1+posx,&dx);  
	posx=NMEA_Comma_Pos(p1,17);								//得到VDOP位置精度因子
	if(posx!=0XFF)gpsx->vdop=NMEA_Str2num(p1+posx,&dx);  
}
//分析GNRMC信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GNRMC_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p1,dx;			 
	uint8_t posx;     
	uint32_t temp;	   
	float rs;  
	p1=(uint8_t*)strstr((const char *)buf,"$GNRMC");//"$GNRMC",经常有&和GNRMC分开的情况,故只判断GPRMC.
	posx=NMEA_Comma_Pos(p1,1);								//得到UTC时间
	if(posx!=0XFF)
	{
		temp=NMEA_Str2num(p1+posx,&dx)/NMEA_Pow(10,dx);	 	//得到UTC时间,去掉ms
		gpsx->utc.hour=temp/10000;
		gpsx->utc.min=(temp/100)%100;
		gpsx->utc.sec=temp%100;	 	 
	}	
	posx=NMEA_Comma_Pos(p1,3);								//得到纬度
	if(posx!=0XFF)
	{
		temp=NMEA_Str2num(p1+posx,&dx);		 	 
		gpsx->latitude=temp/NMEA_Pow(10,dx+2);	//得到°
		rs=temp%NMEA_Pow(10,dx+2);				//得到'		 
		gpsx->latitude=gpsx->latitude*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为° 
	}
	posx=NMEA_Comma_Pos(p1,4);								//南纬还是北纬 
	if(posx!=0XFF)gpsx->nshemi=*(p1+posx);					 
 	posx=NMEA_Comma_Pos(p1,5);								//得到经度
	if(posx!=0XFF)
	{												  
		temp=NMEA_Str2num(p1+posx,&dx);		 	 
		gpsx->longitude=temp/NMEA_Pow(10,dx+2);	//得到°
		rs=temp%NMEA_Pow(10,dx+2);				//得到'		 
		gpsx->longitude=gpsx->longitude*NMEA_Pow(10,5)+(rs*NMEA_Pow(10,5-dx))/60;//转换为° 
	}
	posx=NMEA_Comma_Pos(p1,6);								//东经还是西经
	if(posx!=0XFF)gpsx->ewhemi=*(p1+posx);		 
	posx=NMEA_Comma_Pos(p1,9);								//得到UTC日期
	if(posx!=0XFF)
	{
		temp=NMEA_Str2num(p1+posx,&dx);		 				//得到UTC日期
		gpsx->utc.date=temp/10000;
		gpsx->utc.month=(temp/100)%100;
		gpsx->utc.year=2000+temp%100;	 	 
	} 
}
//分析GNVTG信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_GNVTG_Analysis(nmea_msg *gpsx,uint8_t *buf)
{
	uint8_t *p1,dx;			 
	uint8_t posx;    
	p1=(uint8_t*)strstr((const char *)buf,"$GNVTG");							 
	posx=NMEA_Comma_Pos(p1,7);								//得到地面速率
	if(posx!=0XFF)
	{
		gpsx->speed=NMEA_Str2num(p1+posx,&dx);
		if(dx<3)gpsx->speed*=NMEA_Pow(10,3-dx);	 	 		//确保扩大1000倍
	}
}  
//提取NMEA-0183信息
//gpsx:nmea信息结构体
//buf:接收到的GPS数据缓冲区首地址
void NMEA_Analysis(nmea_msg *gpsx,uint8_t *buf)
{

	NMEA_GNGGA_Analysis(gpsx,buf);	//GNGGA解析 	
	
}




void My_Reset(uint8_t *buf, uint16_t buf_size)
{
	for(uint16_t num=0;num<buf_size;num++)
	{
		buf[num] = 0;
	}
}

//GPS更新
void GPS_Refresh_Set(void)
{
	//if(GPS_message.latitude !=0 && GPS_message.longitude !=0 && GPS_message.posslnum  > 0 )
		//{
			OsdRefresh_Family[_Altitude].Refresh_Flag = Refresh_yes;
			OsdRefresh_Family[_Numllite].Refresh_Flag = Refresh_yes;
			OsdRefresh_Family[_Satellite].Refresh_Flag = Refresh_yes;

			OsdRefresh_Family[_Latitude].Refresh_Flag = Refresh_yes;
			OsdRefresh_Family[_Longitude].Refresh_Flag = Refresh_yes;

			OsdRefresh_Family[_LongitudeFlag].Refresh_Flag = Refresh_yes;
			OsdRefresh_Family[_LatitudeFlag].Refresh_Flag = Refresh_yes;
		//}
}

#define Osd_ShowModuleNum	9
//GPS 16进制数转化成10进制，再把10进制的每一位转换成ASCII的值，写入对应模块地址中
void Gps_ConvertHexToDec(OsdRefresh_Struct *_OsdRefresh_Struct, nmea_msg SrcData)
{
	unsigned char  num,len = 0,size = 0;
	unsigned char  module_code;
	unsigned char  module_num;
	uint32_t DecData,Weight = 0;
	uint32_t Data_,ret;
	int DecData_Altitude;//海拔是整型+
	
	uint8_t tt1,tt2;
	
	for(module_code=0; module_code<Osd_ShowModuleNum;module_code++)
	{
		switch(module_code)
		{
			
			//卫星数
			case 0 :
				DecData = SrcData.posslnum;
				module_num = _Numllite;
				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
				AutoCompletion(_OsdRefresh_Struct[module_num].Module_addr, 2, 0x30);
				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
			
				break;
				
			//海拔
			case 1 :
				module_num = _Altitude;
//				if(SrcData.posslnum  <= 2)
//				{
//					_OsdRefresh_Struct[module_num].Module_addr[0] = osd_Icon_jian;
//					_OsdRefresh_Struct[module_num].Module_addr[1] = osd_Icon_jian;
//					_OsdRefresh_Struct[module_num].Module_addr[2] = osd_Icon_jian;
//					_OsdRefresh_Struct[module_num].Module_addr[3] = osd_Icon_jian;
//					_OsdRefresh_Struct[module_num].Module_addr[4] = osd_M;
//					break;
//				}
				DecData_Altitude = SrcData.altitude / 1000;
				_OsdRefresh_Struct[module_num].Module_addr[4] = 0;//-0x4D;
				DecToHexToAscii(0, DecData_Altitude,_OsdRefresh_Struct[module_num].Module_addr,2);
				AutoCompletion(_OsdRefresh_Struct[module_num].Module_addr, 4, 0x30);
				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
				_OsdRefresh_Struct[module_num].Module_addr[4] = osd_M;//-0x4D;

				break;
			
			//经度值
			case 2 :
				DecData = SrcData.longitude;
				module_num = _Longitude;
				Convert_DegreesMinutesSeconds(DecData, _OsdRefresh_Struct[module_num].Module_addr);
				
				break;
			
			//纬度值
			case 3 :
				DecData = SrcData.latitude;
				module_num = _Latitude;
				Convert_DegreesMinutesSeconds(DecData, _OsdRefresh_Struct[module_num].Module_addr);
				
				break;
			
			//方位
			case 4 :
//				DecData = SrcData.longitude;
//				module_num = _Position;
//				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
//				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
				break;
			
			//俯仰
			case 5 :
//				DecData = SrcData.longitude;
//				module_num = _Pitch;
//				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
//				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
				break;
			
			//卫星状态
			case 6 :
				DecData = SrcData.gpssta;
//				module_num = _Satellite;
//				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
//				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
			if(DecData>=1)
			{
				_OsdRefresh_Struct[_Satellite].Module_addr[0] = osd_Icon_Satellite_1;
				_OsdRefresh_Struct[_Satellite].Module_addr[1] = osd_Icon_Satellite_2;
				_OsdRefresh_Struct[_Satellite].Module_addr[2] = '\r';
			}
			else
			{
				_OsdRefresh_Struct[_Satellite].Module_addr[0] = osd_Icon_jian;
				_OsdRefresh_Struct[_Satellite].Module_addr[1] = osd_NONE;
				_OsdRefresh_Struct[_Satellite].Module_addr[2] = '\r';
			}
				break;
				
			//经度标识
			case 7 :
				DecData = SrcData.ewhemi;
				module_num = _LongitudeFlag;
				_OsdRefresh_Struct[module_num].Module_addr[0] = DecData;

//				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
//				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
				break;
			
			
			//维度标识
			case 8:
				DecData = SrcData.nshemi;
				module_num = _LatitudeFlag;
				_OsdRefresh_Struct[module_num].Module_addr[0] = DecData;
//				DecToHexToAscii(DecData, 0,_OsdRefresh_Struct[module_num].Module_addr,1);
//				SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
				break;
			
			default :
				break;
		}				


		len = 0;
	}
}

/*
//对显示单元不足的位数自动补FillDate
OsdModule_buff 存储数组
MustLen 数组必须的长度
*/
void AutoCompletion(unsigned char *OsdModule_buff, unsigned char MustLen, unsigned char FillDate)
{
	uint8_t Len,Surplus,num;
	
	Len = MyStrlen(OsdModule_buff);
	
	if(Len < MustLen)
	{
		Surplus = MustLen - Len;
		for(num=0;num<Surplus;num++)
		{
			OsdModule_buff[num+Len] = FillDate;
		}
		OsdModule_buff[Surplus+Len] = '\r';
	}
	
}

//大小端转换
static unsigned char buf[Addr_SIZE_SMALL];
void SmallToBig(unsigned char *src)
{
	unsigned char num,val;
	
	num = MyStrlen(src); 
	
	for(val=0; val<num; val++)
	{
		buf[val] = src[num-1-val];
	}
	buf[num] = '\r';
	
	for(val=0; val<num; val++)
	{
		src[val] = buf[val];
	}
}


void RefreshModule(OsdRefresh_Struct *_OsdRefresh_Struct,nmea_msg *SrcMessage, _OsdModuleindex GPS_OsdModule)
{
	Gps_ConvertHexToDec(OsdRefresh_Family,GPS_message);
	
	switch(GPS_OsdModule)
	{	
		//状态
		case _State:
			
			break;

//		//放大 
//		case _Amplifier:

//			break;

//		//缩小
//		case _Reduce:

//			break;

//		//wify
//		case _Wifi:

//			break;

//		//照片
//		case _Photo:

//			break;
//		//录像
//		case _Record:

			break;

		//电量
		case _Power:

			break;
		
		//卫星状态
		case _Satellite:
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[0] =  SrcMessage->gpssta;
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[1] ='\r';
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;
			break;
		
		//卫星数量
		case _Numllite:

			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;

			break;
		
		//海拔
		case _Altitude:
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;
			break;
		
		//经度标识
		case _LongitudeFlag:
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[0] =  SrcMessage->ewhemi;
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[1] ='\r';
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;
			break;

		//经度值
		case _Longitude:
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;
			break;

		//纬度标识
		case _LatitudeFlag:
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[0] =  SrcMessage->nshemi;
			_OsdRefresh_Struct[GPS_OsdModule].Module_addr[1] ='\r';
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;

			break;

		//纬度值
		case _Latitude:
			OsdRefresh_Family[GPS_OsdModule].Refresh_Flag = Refresh_yes;
			break;
		
//		//gps
//		case _Gps:

//			break;
		//方位
		case _Position:

			break;
		
		//俯仰
		case _Pitch:

			break;
		
		default :

			break;
	}
}


//验证不同海拔会不会不一样 显示？？？？？？？？？？？？？
//得到的十进制度分秒，然后分别转换成度分秒，再将度分秒 转换成ASCII保存
unsigned char Convert_DegreesMinutesSeconds(uint32_t SrcDate, unsigned char *Decbuf)
{
	int Degree,Min,Sec;
	unsigned char Degree_buf[8]={0},Min_buf[8]={0},Sec_buf[8]={0};
	
	//转换成度分秒
	Degree = SrcDate/pow((double)10, (double)(5));
	Min = (SrcDate%(uint32_t)(pow((double)10, (double)(5)))) /1000.0*60.0 / 100.0;
	Sec = (SrcDate%(uint32_t)(pow((double)10, (double)(5))))/1000.0 * 60.0 / 1000.0;
	
	if(Degree>999 || Min>99 || Sec>99)
	{
		return 0;
	}
	
		
//	Degree = 100;
//	Min = 12;
//	Sec = 11;
	//将十进制 度 每个位转换成ASCII
	DecToHexToAscii(0,Degree,Degree_buf,2);
	AutoCompletion(Degree_buf, 3, 0x30);
	SmallToBig(Degree_buf);
	
	//将十进制 分 每个位转换成ASCII
	DecToHexToAscii(0,Min,Min_buf,2);
	AutoCompletion(Min_buf, 2, 0x30);
	SmallToBig(Min_buf);
	
	//将十进制 秒 每个位转换成ASCII
	DecToHexToAscii(0,Sec,Sec_buf,2);
	AutoCompletion(Sec_buf, 2, 0x30);
	SmallToBig(Sec_buf);
	
	Decbuf[0] = '\0';
	
	//结合
	strcat((char *)Decbuf,(const char *)Degree_buf);
	//strcat((char *)Decbuf,(const char *)osd_Du); //单位 度
	Decbuf[3] = osd_Du;
	strcat((char *)Decbuf,(const char *)Min_buf);
	//strcat((char *)Decbuf,(const char *)osd_Min); //单位 分
	Decbuf[6] = osd_Sec;
	strcat((char *)Decbuf,(const char *)Sec_buf);
	//strcat((char *)Decbuf,(const char *)osd_Sec);//单位 秒
	Decbuf[9] = osd_Min;
	
	return 1;
}
/*
//将十六进制转为十进制数,再将十进制数每一位转换为Ascii存放在数组里面
data1 如果十六进制数是uint32类型 data2 =0
data2 如果十六进制数是int类型    data1 = 0
Flag =1 unit32_t    Flag=2  int 
*/
void  DecToHexToAscii(uint32_t data1, int data2,unsigned char *strArray, uint8_t Flag)
	{
		unsigned char len = 0,num;
		uint32_t Weight,ret1;
		int ret2;
			
		// input uint32_t
		if(Flag == 1)
		{
			if(data1>= 0) len++; 		//个
			if(data1/10 != 0) len++; 		//十
			if(data1/100 != 0) len++; 		//百
			if(data1/1000 != 0) len++; 	//千
			if(data1/10000 != 0) len++; 	//万
			if(data1/100000 != 0) len++; //十万
			if(data1/1000000 != 0) len++;	//百万
			if(data1/10000000 != 0) len++;	//千万
			if(data1/1000000000 != 0) len++;	//十亿
			
			ret1 = data1 ;
			for(num = len; num>0; num--)
			{
				switch(num)
				{
					case 1: //个
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						break;

					case 2: //十
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % Weight;
						break;

					case 3://百位
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % Weight;
						break;

					case 4:
						Weight = pow((double)10, (double)(num-1));			
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % Weight;
						break;

					case 5:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;
					
					case 6:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;

					case 7:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;

					case 8:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;

					case 9:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;

					case 10:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret1 / Weight);//得到每个位的值 1-9  个
						ret1 = ret1 % (Weight);
						break;
					
					default:
						break;
				}
				//_OsdRefresh_Struct[module_num].Module_addr[num] /= (Weight/10);
				strArray[num-1] = strArray[num-1] + 0x30; // 转换为ASCII值
			}
			strArray[len] = '\r';
			len = 0;
		}
		
		//input int
		else if(Flag == 2)
		{
			 len++; 		//个
			if(data2/10 != 0) len++; 		//十
			if(data2/100 != 0) len++; 		//百
			if(data2/1000 != 0) len++; 	//千
			if(data2/10000 != 0) len++; 	//万
			if(data2/100000 != 0) len++; //十万
			ret2 = data2 ;
			for(num = len; num>0; num--)
			{
				switch(num)
				{
						
					case 1: //
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret2 / Weight);//得到每个位的值 1-9  个
						break;

					case 2:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret2 / Weight);//得到每个位的值 1-9  个
						ret2 = ret2 % Weight;
						break;

					case 3://百位
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret2 / Weight);//得到每个位的值 1-9  个
						ret2 = ret2 % Weight;
						break;

					case 4:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret2 / Weight);//得到每个位的值 1-9  个
						ret2 = ret2 % Weight;
						break;

					case 5:
						Weight = pow((double)10, (double)(num-1));
						strArray[num-1] = (ret2 / Weight);//得到每个位的值 1-9  个
						ret2 = ret2 % (Weight);
						break;
					
					default:
						break;
				}
				//_OsdRefresh_Struct[module_num].Module_addr[num] /= (Weight/10);
				strArray[num-1] = strArray[num-1] + 0x30; // 转换为ASCII值
			}
			
			strArray[len] = '\r';
			len = 0;
		}
		
		//SmallToBig(_OsdRefresh_Struct[module_num].Module_addr);
	}
	